package pers.cz.postgirl.core.store;

import pers.cz.postgirl.exception.ErrorCode;
import pers.cz.postgirl.exception.StoreException;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: postgirl-client
 * @description: 本地存储
 * @author: Cheng Zhi
 * @create: 2023-06-05 13:49
 **/
public class MemoryStore implements Store {

    private static Map<String, Object> cache = new HashMap<String, Object>();

    @Override
    public void set(String key, Object value) {
        cache.put(key, value);
    }

    @Override
    public Object get(String key) {

        Object o = cache.get(key);
        if (o == null) {
            throw new StoreException(ErrorCode.STORE_GET_MEMORY_ERROR, key);
        }
        return o;
    }

}
